<?php
namespace app\index\controller;
use app\index\controller\BaseController;
use think\Db;

class CartController extends BaseController {

	function index(){
		//获取购物列表
		$cart_list = db('good_cart')
						->where('user_id',session('user_id'))
						->select();
		
		$agent_goods = array();
		$goods_ids='';
		foreach($cart_list as $key=>$value){
			$goods_ids=$goods_ids.$value['goods_id'].',';
			$agent_goods[$value['agent_id']][] = $value;
		}
		$this->assign('agent_goods',$agent_goods);	
		
		//计算金额
		$total_money = db('goods')
						->where('goods_id','in',substr($goods_ids,0,strlen("$goods_ids")-1))
						->sum('cost_price');
		
		$this->assign('total_money',$total_money);	
		
		return $this->fetch();
	}
	
	

}
